package com.kgc.smbms.service.impl;

import com.kgc.smbms.bean.User;
import com.kgc.smbms.mapper.UserMapper;
import com.kgc.smbms.service.UserService;
import com.kgc.smbms.utils.PageSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created On : 12/8/2022.
 * <p>
 * Author : huayu
 * <p>
 * Description: UserServiceImpl  用户 业务层 实现类
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //校验用户登录信息 是否正确
    @Override
    public User checkLoginUser(String loginUserCode, String loginUserPassword) {
        return userMapper.selectUserByCOdeAndPwd(loginUserCode,loginUserPassword);
    }

    //条件 分页 查询  用户列表
    @Override
    public List<User> getUserListByQueryNameAndQueryUserRole(String queryName, Integer QueryUserRole, PageSupport pageSupport) {
        return userMapper.SelectUserListByQueryNameAndQueryUserRole(queryName,QueryUserRole,pageSupport);
    }

    //根据id查看用户详情
    @Override
    public User getUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    //修改用户信息
    @Override
    public boolean modUserInfo(User userForm) {
        if(userMapper.updateUserInfo(userForm) > 0){
            return true;
        }else{
            return false;
        }

    }

    //根据用户id删除用户信息
    @Override
    public boolean delUserById(Integer id) {
        if(userMapper.delUserById(id) > 0){
            return true;
        }else {
            return  false;
        }

    }

    //添加用户信息
    @Override
    public boolean addUserInfo(User userForm) {
        if(userMapper.insertUserInfo(userForm) > 0){
            return true;
        }else {
            return false;
        }

    }

    //修改用户密码
    @Override
    public boolean userPasswordMod(Integer userId,String newPassword) {
        if(userMapper.userPasswordMod(userId,newPassword) > 0){
            return true;
        }else {
            return false;
        }
    }

    //条件查询用户列表  总数
    @Override
    public int getUserListTotalByQueryNameAndQueryUserRole(String queryName, Integer QueryUserRole) {
        return (int)userMapper.selectUserListTotalByQueryNameAndQueryUserRole(queryName, QueryUserRole).get("total").longValue();

    }

    //根据用户编码查看用户详情
    @Override
    public User getUserByUserCode(String userCode) {
        return userMapper.selectUserByUserCode(userCode);
    }


}
